package com.zhiyou100.controller;

import java.io.File;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.zhiyou100.model.Progress;
import com.zhiyou100.service.ProgressService;
import com.zhiyou100.vo.ResponseVo;

@RestController
public class ProgressController {
	
	@Autowired
	private ProgressService progressService;
	@GetMapping("/progresss/{projectId}")
	public ResponseVo<String> findByProjectId(@PathVariable int projectId){
		
		progressService.findByProjectId(projectId);
		
		return new ResponseVo<String>(200, "请求成功", null);
		
		
	}
	@GetMapping("/progresss/{id}")
	public ResponseVo<String> fingById(@PathVariable int id){
		
		progressService.fingById(id);
		
		return new ResponseVo<String>(200, "请求成功", null);
		
		
	}
	@PostMapping("/progresss")
	public ResponseVo<String> add(Progress progress,MultipartFile file,HttpServletRequest request){
		
		String web=request.getServletContext().getRealPath("/");
		String path=web+"/"+file.getOriginalFilename();
		
		try {
			file.transferTo(new File(path));
		} catch (IllegalStateException | IOException e) {
			e.printStackTrace();
		}
		progress.setLogo(file.getOriginalFilename());
		progressService.add(progress);
		return new ResponseVo<String>(200, "修改成功",null);
		
	}

}
